package com.yl.ydk.ui.activity

import android.content.Intent
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.yl.ydk.R
import com.yl.ydk.base.BaseActivity
import com.yl.ydk.presenter.contract.LiveDetailContract
import com.yl.ydk.presenter.impl.LiveDetailImpl
import com.blankj.utilcode.utils.ToastUtils
import com.google.gson.Gson
import com.yl.ydk.bean.LiveDetailBean
import kotlinx.android.synthetic.main.activity_live_detail.*
import kotlinx.android.synthetic.main.roob_bar.*

class LiveDetailActivity : BaseActivity(), LiveDetailContract.View, View.OnClickListener {

    private var liveId: Int? = null
    private val mPresenter = LiveDetailImpl()
    private var playUrl:String? = null
    private var data: LiveDetailBean? = null

    override fun getLayoutId(): Int = R.layout.activity_live_detail

    override fun attachView() {
        mPresenter.attachView(this)
    }

    override fun detachView() {
        mPresenter.detachView()
    }

    override fun initView() {
        tvTitle.text = "医生直播"
        rlBack.setOnClickListener(this)
        btnLive.setOnClickListener(this)
        liveId = intent.getIntExtra("live_id", 0)
        mPresenter.getLiveDetail(this, "live_id", liveId.toString())

    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.rlBack -> {
                finish()
            }
            R.id.btnLive -> {
                val intent = Intent(this,TXCloudVideoActivity::class.java)
                intent.putExtra("play_url",playUrl)
                intent.putExtra("data", Gson().toJson(data))
                startActivityIn(intent,this)
                finish()
            }
        }
    }


    override fun getIvImage(): ImageView = ivImage

    override fun getTvName(): TextView  = tvName

    override fun getIvHead(): ImageView  = ivHead

    override fun getTvDName(): TextView  = tvDName

    override fun getTvDesc(): TextView  = tvDesc

    override fun getTvStartTime(): TextView = tvStartTime

    override fun getPushUrl(playUrl: String) {
        this.playUrl = playUrl
    }

    override fun getLiveDetailBean(data: LiveDetailBean) {
        this.data = data
    }

    override fun showError(message: String?) {
        ToastUtils.showLongToastSafe(message)
    }

}